﻿using SqlSugar;
using SupplyChain.Infrastructure;
using SupplyChain.Infrastructure.Implement;
using SupplyChain.Infrastructure.Interface;

namespace SupplyChain.Write.API.Extensions
{
    public static class DependencyInjection
    {
        public static void AddSqlSugarContext(this IServiceCollection services, IConfiguration configuration)
        {
            // 注册 SqlSugar 客户端
            services.AddScoped(provider =>
            {
                var sugarDBContext = provider.GetRequiredService<SugarDBContext>();
                return sugarDBContext.InitDBContext("DefaultConnection"); // 默认连接字符串名称
            });

            // 注册泛型仓储
            services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));

            // 注册 SugarDBContext
            services.AddScoped(provider => new SugarDBContext(configuration));
        }
    }
}
 